home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / SelectProtocol / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  6KB  |  245 lines

  1.  
  2. /*
  3.  
  4.   Select Protocol Door (C) 1995 Deluxe Software! - Written By Dominic Clifton
  5.  
  6.   Functions of door:
  7.  
  8.   - Check User.CallData.Protocol, if 0 display list of availiable protocols and let
  9.     user select one, if set to 1 or more then:
  10.  
  11.     - take 1 from the CallData.Protocol value, and return the value as a string
  12.       in N_ND->DoorReturn
  13.  
  14.   - You must also only display protocol that are availiable for the type of transfer
  15.     selected ( i.e. only show protocols with Allow_UL when type UPLOAD is set
  16.     (see Argv[0])  Bi-Directional protocols MUST have Allow_UL AND Allow_DL set..
  17.   - Check validity of N_ND->DoorReturn (ie, must be lower than amount in
  18.     BBSGlobal->Protocols)
  19.  
  20.  
  21.   Todo
  22.   ====
  23.  
  24.   * Loop or CANCEL if invalid protocol has been selected
  25.  
  26.   * Make nice and colourfull.
  27.  
  28.   * Add Config to change colours and or display special or user screen before
  29.     and after selecting protocols.
  30.  
  31.     (Make all text output configurable ?)
  32.  
  33. */
  34.  
  35. #include <exec/types.h>
  36. #include <exec/memory.h>
  37. #include <dos/dos.h>
  38. #include <clib/exec_protos.h>
  39. #include <clib/dos_protos.h>
  40. #include <clib/alib_protos.h>
  41.  
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <stdio.h>
  45. #include <ctype.h>
  46. #include <time.h>
  47.  
  48.  
  49. #ifdef __SASC
  50. int CXBRK(void) { return(0); }
  51. int _CXBRK(void) { return(0); }
  52. void chkabort(void) {}
  53. #endif
  54.  
  55. #include <HBBS/ANSI_Codes.h>
  56. #include <HBBS/Defines.h>
  57. #include <HBBS/types.h>
  58. #include <HBBS/structures.h>
  59. #include <HBBS/hbbscommon_protos.h>
  60. #include <HBBS/hbbscommon_pragmas.h>
  61. #include <HBBS/Hbbsnode_protos.h>
  62. #include <HBBS/Hbbsnode_pragmas.h>
  63. #include <HBBS/release.h>
  64. char *versionstr="$VER: SelectProtocol "RELEASE_STR;
  65.  
  66. char versionstr[]="$VER: SelectProtocol 1.0";
  67. struct Library *HBBSCommonBase=NULL;
  68. struct Library *HBBSNodeBase=NULL;
  69.  
  70. struct BBSGlobalData *BBSGlobal=NULL;
  71. struct NodeData *N_ND=NULL;
  72. int N_NodeNum=-1;
  73.  
  74. static VOID cleanup(ULONG num)
  75. {
  76.   if (HBBSNodeBase)
  77.   {
  78.     HBBS_CleanUpDoor();
  79.     CloseLibrary (HBBSNodeBase);
  80.   }
  81.  
  82.   if (HBBSCommonBase)
  83.   {
  84.     HBBS_CleanUpCommon();
  85.     CloseLibrary (HBBSCommonBase);
  86.   }
  87.  
  88.   if (num) printf("Door Error = %d\n",num);
  89.  
  90.   exit(0);
  91. }
  92.  
  93. static VOID init(char *name)
  94. {
  95.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  96.   {
  97.     cleanup(1);
  98.   }
  99.  
  100.   if (!(HBBS_InitCommon()))
  101.   {
  102.     cleanup(2);
  103.   }
  104.  
  105.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  106.   {
  107.     cleanup(3);
  108.   }
  109.  
  110.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  111.   {
  112.     cleanup(4);
  113.   }
  114.   SetProgramName(name);
  115. }
  116.  
  117. BOOL ProtocolOK(struct ProtocolNode *pnode,char *param)
  118. {
  119.   if ( ((pnode->allow_ul) && (!stricmp("UPLOAD",param)))
  120.        ||
  121.        ((pnode->allow_dl) && (!stricmp("DOWNLOAD",param))) )
  122.   {
  123.     return(TRUE); // Protocol Is OK
  124.   }
  125.  
  126.   return(FALSE);
  127. }
  128.  
  129. void DoorMain(int argc,char *argv[])
  130. {
  131.   int loop;
  132.   struct ProtocolNode *pnode;
  133.   char outstr[BIG_STR];
  134.   int number;
  135.   int displayed=0;
  136.   BOOL Done=FALSE;
  137.  
  138.   DOOR_Return("CANCEL");
  139.  
  140.   if (number=N_ND->User.CallData.Protocol)
  141.   {
  142.     number--; // default protocol if offset by one.
  143.     pnode=(struct ProtocolNode *)GetNode(BBSGlobal->ProtocolList,number);
  144.     if (ProtocolOK(pnode,argv[2]))
  145.     {
  146.       sprintf(N_ND->DoorReturn,"%d",number);
  147.       return;
  148.     }
  149.     else DOOR_WriteText("Your default protocol is not valid for this type of transfer\r\n"
  150.                         "Please select a different protocol from the list.\r\n");
  151.  
  152.   }
  153.  
  154.   // Display All Protocols
  155.   for (loop=0;loop<BBSGlobal->Protocols;loop++)
  156.   {
  157.     pnode=(struct ProtocolNode *)GetNode(BBSGlobal->ProtocolList,loop);
  158.  
  159.     if (ProtocolOK(pnode,argv[2]))
  160.     {
  161.       displayed++;
  162.       sprintf(outstr,"%-02d) %s\r\n",displayed,pnode->node.ln_Name);
  163.       DOOR_WriteText(outstr);
  164.     }
  165.   }
  166.  
  167.   if (displayed)
  168.   {
  169.     // Ask For Protocol, or return to select default protocol or first protcol in list
  170.     // if default protocol is not set for the user.
  171.  
  172.     do
  173.     {
  174.       DOOR_WriteText("\r\nSelect Protocol For ");
  175.       DOOR_WriteText(argv[2]);
  176.       DOOR_WriteText(" >");
  177.  
  178.       strcpy(N_ND->CharsAllowed,"0123456789");
  179.  
  180.       DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_USECHARS|GL_IMMEDIATE,'\0',BBSGlobal->Protocols>9 ? 2 : 1,0,NULL);
  181.  
  182.       if (N_ND->OnlineStatus=OS_ONLINE)
  183.       {
  184.         if ((N_ND->CurrentLine[0]==0) || (sscanf(N_ND->CurrentLine,"%d",&number)==0))
  185.         {
  186.           // blank line, or no number.
  187.           number=1;
  188.         }
  189.  
  190.  
  191.         if (number>=1 && number <=displayed)
  192.         {
  193.  
  194.           loop=0;
  195.           displayed=0;
  196.           do
  197.           {
  198.             pnode=(struct ProtocolNode *)GetNode(BBSGlobal->ProtocolList,loop);
  199.             if (ProtocolOK(pnode,argv[2]))
  200.             {
  201.               displayed++;
  202.             }
  203.             loop++;
  204.           } while (number!=displayed);
  205.  
  206.           sprintf(outstr,ANSI_RESET ANSI_FG_CYAN "Selected Protocol "ANSI_FG_WHITE"%d "ANSI_FG_CYAN"- "ANSI_FG_WHITE"%s\r\n",number,pnode->node.ln_Name);
  207.           DOOR_WriteText(outstr);
  208.  
  209.           sprintf(outstr,"%d",loop-1);
  210.           DOOR_Return(outstr);
  211.           Done=TRUE;
  212.         }
  213.         else
  214.         {
  215.           // number too high or low.
  216.  
  217.           DOOR_WriteText("Invalid Option!\r\nSelecting protocol 1\r\n");
  218.         }
  219.       }
  220.       else Done=TRUE;
  221.     } while (!Done);
  222.   }
  223.   else DOOR_WriteText("\r\nNo Protocols Availiable For This Type Of Transfer!\r\n\r\n");
  224.  
  225. }
  226.  
  227. int main(int argc,char *argv[])
  228. {
  229.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  230.   {
  231.     printf("Invalid/No Paramaters for door!\n");
  232.     exit (20);
  233.   }
  234.   init("SelectProtocol");
  235.  
  236.   if (BBSGlobal=HBBS_GimmeBBS())
  237.   {
  238.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  239.     {
  240.       DoorMain(argc,argv);
  241.     }
  242.   }
  243.   cleanup(0);
  244. }
  245.